#include <QtGui/QApplication>
#include "player.h"
#include <QTranslator>
#include "settings.h"
#include "playlist.h"
#include <QDir>
#include <QLocale>
#include <QTextCodec>
#include <Python.h>
#include "pyapi.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

#ifdef Q_OS_WIN
    Settings::path = QString(argv[0]).section('\\', 0, -2);
#endif
    Settings::initSettings();
    initAPI();

    //translate moonplayer
    QTranslator translator;
    QDir path(Settings::path);
    translator.load(path.filePath("moonplayer_" + QLocale::system().name()));
    a.installTranslator(&translator);

    Player w;
    w.show();

    if (argc > 1)
    {
#ifdef Q_OS_WIN
        QTextCodec* codec = QTextCodec::codecForLocale();
        QString file = codec->toUnicode(argv[1]);
#else
        QString file = QString::fromUtf8(argv[1]);
#endif
        if (file.endsWith(".m3u") || file.endsWith(".xspf")) //playlist
            w.playlist->addList(file);
        else
            w.playlist->addFileAndPlay(file, file);
    }
    a.exec();
    Py_Finalize();
    return 0;
}
